package view.listeners;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTable;

import controller.Controller;

import model.TableModel;

import view.MainFrame;
import view.components.IpAddressTable;
import view.components.IpAddressTablePopup;
import view.components.PopUpBuilder;

public class IpAddressTableListener implements MouseListener {

	private IpAddressTable addressTabel;
	private TableModel model;

	public IpAddressTableListener(IpAddressTable ipAddressTable) {
		this.addressTabel = ipAddressTable;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		JTable tabel = (JTable) e.getSource();
		model = addressTabel.getModel();
		System.out.println();
		int rowNr = tabel.getSelectedRow();
		if (rowNr!=-1){
		
		
	
			String ipAdress = model.getValueAt(rowNr, 0).toString();
		String infoText = model.getValueAt(rowNr, 1).toString();
		System.out.println(ipAdress + infoText);

		if (e.getButton() == 3) {
			MainFrame frame =  Controller.getInstance().getGuiBuilder().getFrame();
			new IpAddressTablePopup(e.getXOnScreen()-frame.getX(), e.getYOnScreen()-frame.getY(), ipAdress, infoText, addressTabel);
		}}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
